package com.yu.footballpromotionliveadmin.controller;


import com.yu.footballpromotionliveadmin.dto.DTO;
import com.yu.footballpromotionliveadmin.page.PageInfo;
import com.yu.footballpromotionliveadmin.pojo.CompetitionRecord;
import com.yu.footballpromotionliveadmin.service.CompetitionRecordService;
import com.yu.footballpromotionliveadmin.vo.CompetitionRecordView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
class CompetitionRecordController {

    @Autowired
    CompetitionRecordService competitionRecordService;

    @GetMapping("/competitionRecord")
    public DTO<CompetitionRecord> getAllLiveAdmin() throws Exception {

        return competitionRecordService.getAllCompetitionRecords();
    }

    @GetMapping("/getcompetitionRecord/{crno}")
    public DTO<CompetitionRecord> getLiveAdminById(@PathVariable("crno") String crno) throws Exception {

        return competitionRecordService.getCompetitionRecordById(crno);
    }


    @PostMapping("/competitionRecord")
    public DTO<CompetitionRecord> getLiveAdminById(@RequestBody CompetitionRecordView competitionRecord) throws Exception {

        return competitionRecordService.addCompetitionRecord(competitionRecord);
    }


    @PatchMapping("/competitionRecord")
    public DTO<CompetitionRecord> updateLiveAdmin(@RequestBody CompetitionRecordView competitionRecord) throws Exception {

        return competitionRecordService.updateCompetitionRecord(competitionRecord);
    }

    @GetMapping("/getCompetitionRecordByPage")
    public DTO<CompetitionRecord> ByPage(PageInfo pageInfo) throws Exception {
        DTO<CompetitionRecord> dto = competitionRecordService.getCompetitionRecordsByPage(pageInfo);
        System.out.println(dto);
        return dto;
    }

    @DeleteMapping("/competitionRecord/{crno}")
    public DTO<CompetitionRecord> deleteByKey(@PathVariable("crno") String crno) throws Exception {

        return competitionRecordService.deleteCompetitionRecord(crno);
    }
}
